/**
 * org.vz.product.collect.maintain.web
 * @since : jdk 1.8
 */
package org.vz.product.collect.maintain.web;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.vz.product.collect.maintain.config.MonitoredIps;

/**
 * @author      lanxuyu
 * @CreateTime  2017年10月9日 下午2:26:03
 * @version     1.0.0
 * @description TODO
 */
@Controller
@RequestMapping("/monitoring")
public class MonitoringController {
	@Autowired
	MonitoredIps monitoredIps;
	private String defaultIp="";
	
	@RequestMapping("/manage")
	public String managerPage(Map<String,Object> front){
		String[] ips = monitoredIps.getIps();
		if(ips==null){
			ips=new String[1];
			ips[0]="localhost:8080";
		}
		List<String> address = Arrays.asList(ips);
		front.put("ips", address);
		if("".equals(defaultIp)||defaultIp==null){
			defaultIp= address.get(0);
		}
		
		front.put("defaultIp",defaultIp);
		
		return "monitoring";
	}
	@RequestMapping("/setIp")
	@ResponseBody
	public String managerPage(String ip,Map<String,Object> front){
		defaultIp=ip;
		front.put("defaultIp",defaultIp);
		return "success";
		
	}
	
}
